<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Title</title>
</head>
<body>

</body>
<script>
	
	Function.prototype.myCall = function(context,...arg){
		// context---->fn2
		// this------->fn1.myCall
		if(typeof context === "string" || typeof context === "boolean" || typeof context==="number"){
			context = new Object(context);
		}else if(context===undefined || context ===null){
			context = window;
		}
		let fnName = Math.random().toString(36).slice(2);
		context[fnName] = this;// context["xxx"]=fn1.myCall;
		context[fnName](...arg);// context["xxx"]()======> fn1.myCall()->this为context;
		delete context[fnName];
		// 调用fn1.myCall(),this-->fn2
	}
	function fn1() {
		console.log(1);
	}
	function fn2() {
		console.log(2);
	}
	// 调用fn1,并将fn1中的this指向为fn2
	fn1.call(fn2);// 1
	// 调用fn1.call，并将this指向为fn1.call
	fn1.call.call(fn2);// 2
</script>
</html>